﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using AMatysiak.Methods;

namespace AMatysiak.Web
{
    public static class WebSite
    {
        public static StreamReader OpenStream(string url)
        {
            HttpWebResponse rp = Open(url);

            Stream stream = rp.GetResponseStream();
            return new StreamReader(stream);
        }

        public static HttpWebResponse Open(string url)
        {
            WebRequest rq = WebRequest.Create(url);
            rq.Credentials = CredentialCache.DefaultCredentials;
            return (HttpWebResponse)rq.GetResponse();
        }

        public static string[] ReadPage(string url)
        {
            StreamReader reader = OpenStream(url);
            List<string> page = new List<string>();

            string line = "";
            while (true)
            {
                line = reader.ReadLine();
                if (line.IsEmpty())
                    break;

                page.Add(line);
            }

            return page.ToArray();
        }
    }
}
